package Client;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import GUI.Comunica;
import Net.ListenSocket;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author mboungou
 */
public class ComunicaTCPClient /*extends Thread*/ {
    private BufferedWriter out;
    private BufferedReader in;
    private Socket client;
    private ListenSocket ls;
   
    public ComunicaTCPClient(String host,int port) {
         try
        {
            System.out.println("Connexion vers "+host+":"+port+"...");
            initStreams(new Socket(host,port));
        }
        catch (Exception e)
        {
            System.err.println(e);
        }
    }
    ///////////////////////////////////////////////
    ///////////////////////////////////////////////
    public void initStreams(Socket s)
    {
        try
        {
            client=s;
            out= new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
            in= new BufferedReader(new InputStreamReader(client.getInputStream()));
            ls=new ListenSocket(in);            
            ls.start();
            new Comunica("TD4_client",ls,out).setVisible(true);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    ///////////////////////////////////////////////
    ///////////////////////////////////////////////
     public static void main(String args[]) throws IOException {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
               new ComunicaTCPClient("10.1.1.17",3500);               
               
               //new Comunica("TD3_B",in2,out2).setVisible(true);
            }
        });
    }
     
     
}

